package com.example.mycarcalling.activity;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.mycarcalling.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class ShowPersonDialog {

    public final static String TAG = ShowPersonDialog.class.getSimpleName();

    private AlertDialog showPersonDialog = null;
    private FloatingActionButton fabBack = null;
    private ImageView ivPerson = null;
    private TextView tvLicensePlate = null;
    private TextView tvCarModel = null;
    private TextView tvCarColor = null;
    private TextView tvPersonNickName = null;

    private View inflate = null;

    public TextView getTvLicensePlate() {
        return tvLicensePlate;
    }

    public TextView getTvCarModel() {
        return tvCarModel;
    }

    public TextView getTvCarColor() {
        return tvCarColor;
    }

    public TextView getTvPersonNickName() {
        return tvPersonNickName;
    }

    public ShowPersonDialog(Context context){
        inflate = View.inflate(context, R.layout.dialog_pick_up_person,null);


        showPersonDialog = new AlertDialog.Builder(context)
                .setView(inflate)
                .create();

        fabBack = inflate.findViewById(R.id.fab_person_dialog);
        ivPerson = inflate.findViewById(R.id.iv_person_dialog);
        tvLicensePlate = inflate.findViewById(R.id.tv_license_plate_dialog);
        tvCarModel = inflate.findViewById(R.id.tv_car_model_dialog);
        tvCarColor = inflate.findViewById(R.id.tv_car_color_dialog);
        tvPersonNickName = inflate.findViewById(R.id.tv_person_nickname_dialog);

        fabBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });



        //设置图片圆角角度
        RoundedCorners roundedCorners = new RoundedCorners(100);
        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300);

        Glide.with(context)
                .asGif()
                .load(R.mipmap.person_dialog)
                .apply(options)
                .into(ivPerson);
    }

    public void show() {
        showPersonDialog.show();
    }

    public void dismiss() {
        showPersonDialog.dismiss();
    }
}
